<template>
	<view>
		<view class="content">
			<c-product-list :list="product_list"></c-product-list>
		</view>
		<s-no-data v-if="product_list.length<=0&&moreData===false" :imgUrl="$s.config.getConfig('NoDataImgUrlA')">
			{{$s.config.getConfig('NoDataTitle')}}
		</s-no-data>
		<s-loadmore v-if="moreData"></s-loadmore>
		<s-nomore v-if="product_list.length>0&&moreData===false"></s-nomore>
		<s-scroll-top :scrollTop="scrollTop"></s-scroll-top>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				scrollTop: 0,
				paging:null,
				moreData:true,
				product_list:[],//商品列表
			}
		},
		async onShow() {
			await this.getCollection()
		},
		methods: {
			async getCollection(){
				const paging =  this.$s.model.product.getCollection()
				this.paging = paging
				const res = await paging.getMoreData()
				if (!res) {
					return
				}
				this.product_list = res.accumulator
				this.moreData = res.moreData
			}
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop
		},
		//下拉刷新
		async onPullDownRefresh() {
			await this.getCollection()
			uni.stopPullDownRefresh()
		},
		//上拉加载更多
		async onReachBottom() {
			const res = await this.paging.getMoreData()
			if(!res){
				return
			}
			this.product_list = res.accumulator
			this.moreData = res.moreData
		}
	}
</script>

<style lang="scss" scoped>
@import 'collection.scss';
</style>
